// 综合分析报表mixins
import * as producqQrcode from '@src/api/productQrcode';

const BhAnalysisMixin = {
    data(){
        return {
            relationTypeParams: { // 根据超级二维码模版得到对应的产品类型
                pageNum:1,
                pageSize:10,
                qrcodeTemplateId: '',
                qrcodeId: ''
            },
            mHasNextPage: false, // 是否有下一页
            mProductTypeList: []
        }
    },
    methods: {
        // 产品类型加载更多
        catalogLoadmore(){
            if(!this.mHasNextPage) return;
            this.getRelationType();
        },
        // 获取产品类型数据
        async getRelationType(id){
            try{
                if(id || id === ''){
                    this.relationTypeParams.pageNum = 1;
                    this.mProductTypeList = [];
                }
                this.relationTypeParams.qrcodeTemplateId = this.echartParams.templateId;
                this.relationTypeParams.qrcodeId = this.qrCodeId;

                const { success, message, result } = await producqQrcode.getRelationType(this.relationTypeParams);
                if(!success) return this.$message.error(message);

                this.mHasNextPage = result.hasNextPage;
                const data = result.list || [];
                this.mProductTypeList = this.mProductTypeList.concat(data);
                if(result.hasNextPage) this.relationTypeParams.pageNum++;
            }catch(err){
                console.log('getRelationType', err);
            }
        },
    },
    directives: {
      'loadmore': {
        bind (el, binding) {
          const SELECT_DOM = el.querySelector('.el-select-dropdown .el-select-dropdown__wrap');
          SELECT_DOM.addEventListener('scroll', () => {
            const condition = SELECT_DOM.scrollHeight - SELECT_DOM.scrollTop <= SELECT_DOM.clientHeight;
            if(condition) binding.value();
          })
        }
      }
    },
}

export default BhAnalysisMixin;